package com.kingbook.api.filter;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.*;
import java.io.IOException;

/**
 * 2015年8月7日 下午12:52:53
 * Version 1.0
 */
 
public class IngressFilter implements Filter{

	static Logger logger = LoggerFactory.getLogger(IngressFilter.class);
	FilterConfig filterConfig = null;
    String encoding = null;   

    //第一次调用时执行，只执行一次
	@Override
	public void init(FilterConfig filterConfig) throws ServletException {
		this.filterConfig = filterConfig;
	    this.encoding = filterConfig.getInitParameter("encoding");   
		logger.debug("[IngressFilter]init... ");
		
	}
	
	//服务器关闭时执行，只执行一次
	@Override
	public void destroy() {
		this.filterConfig = null;
		logger.debug("[IngressFilter]destroy... ");
	}

	//每次请求时执行，可以使用<dispatcher>过滤
//	  <dispatcher>REQUEST</dispatcher>
//    <dispatcher>FORWARD</dispatcher>
//    <dispatcher>INCLUDE</dispatcher>
//    <dispatcher>ERROR</dispatcher>
//    <dispatcher>ASYNC</dispatcher>
	@Override
	public void doFilter(ServletRequest request, ServletResponse response,FilterChain chain) throws IOException, ServletException {

		logger.debug("[IngressFilter]doFilter... ");
		chain.doFilter(request, response);
	}
 
}